def read(path='dictionary.txt'):
    with open(path, 'r', encoding='utf-8') as f:
        passwords = f.readlines()
    return passwords


def sort(passwords):
    '''密码列表去重'''
    return list(set(passwords))


def write(passwords, path='dictionary.txt'):
    '''将密码列表写入字典'''
    with open(path, 'w', encoding='utf-8') as f:
        f.writelines(passwords)


def add_password(password, path='dictionary.txt'):
    '''向字典文件中增加密码'''
    with open(path, 'a', encoding='utf-8') as f:
        # 文件最后要有一行空行以便后续添加密码
        f.write(password + '\n')


if __name__ == '__main__':
    list = sort(read())
    print(list[0])
    # write(list, 'dict.txt')
    # add_password('qw2', 'dict.txt')

